﻿using Model;
using MySql.Data.EntityFrameworkCore.DataAnnotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using Tool;
using TP5Like.DBModelValidate;

namespace TP5Like.DBModel
{
    [MySqlCharset("utf8mb4")] //字符集,需要引用MySql.Data.EntityFrameworkCore
    [MySqlCollation("utf8mb4_general_ci")] //排序规则
    [Table("Myaddress", Schema = "manager")]
    public class MyAddress
    {

        [JsonProperty("id")]
        [Required]
        public int Id { get; set; }

        [JsonProperty("province")]
        [StringLength(maximumLength: 256)]
        public string Province { get; set; }

        //[JsonProperty("city")]
        [StringLength(maximumLength: 256)]
        //[Required(ErrorMessage = "城市不能为空1111")]
        //[CustomRequire(ErrorMessage = "城市不能为空1111")]
        public string City { get; set; }

        [JsonProperty("area")]
        [StringLength(maximumLength: 256)]
        public string Area { get; set; }

        [JsonProperty("street")]
        [StringLength(maximumLength: 256)]
        public string Street { get; set; }

        //[NotMapped]
        private DataDBContext _context;

        //[NotMapped]
        //private int Myid;
        public MyAddress(DataDBContext context)
        {
            _context = context;
            //Myid = id;
        }



        [NotMapped]
        public List<Address> address
        {
            get
            {
                if (this.Id != 0)
                {
                    return _context.Addresses.Where(x => x.Id == this.Id).ToList();
                }
                else
                {
                    return null;
                }

            }
            set
            {

            }
        }
    }
}
